package xyz.zhouzhousag.server.controller;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;
import xyz.zhouzhousag.server.pojo.entity.BaseResponse;
import xyz.zhouzhousag.server.pojo.entity.SysLog;
import xyz.zhouzhousag.server.service.SysLogService;

import javax.annotation.Resource;

/**
 * 系统日志(SysLog)表控制层
 *
 * @author Yin.Liu8
 * @since 2021-09-27 10:43:48
 */
@RestController
@RequestMapping("sysLog")
public class SysLogController {
    /**
     * 服务对象
     */
    @Resource
    private SysLogService sysLogService;

    /**
     * 分页查询
     *
     * @param sysLog      筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @GetMapping
    public BaseResponse<Page<SysLog>> queryByPage(SysLog sysLog, PageRequest pageRequest) {
        return BaseResponse.success(this.sysLogService.queryByPage(sysLog, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public BaseResponse<SysLog> queryById(@PathVariable("id") Long id) {
        return BaseResponse.success(this.sysLogService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param sysLog 实体
     * @return 新增结果
     */
    @PostMapping
    public BaseResponse<SysLog> add(SysLog sysLog) {
        return BaseResponse.success(this.sysLogService.insert(sysLog));
    }

    /**
     * 编辑数据
     *
     * @param sysLog 实体
     * @return 编辑结果
     */
    @PutMapping
    public BaseResponse<SysLog> edit(SysLog sysLog) {
        return BaseResponse.success(this.sysLogService.update(sysLog));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public BaseResponse<Boolean> deleteById(Long id) {
        return BaseResponse.success(this.sysLogService.deleteById(id));
    }

}

